﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Irony.Parsing;
using NMF.Languages.AnyText.ClassConstruction;

namespace NMF.Languages.AnyText
{
    public class Identifier : DataTypeTerminal
    {
        private static TypeReference type = new StringType();

        public Identifier(string name, IdentifierTerminal baseTerminal)
            : base(name)
        {
            this.Rule = baseTerminal;
            DefaultValues = new List<string>();
        }

        public bool IsUnique { get; set; }

        public List<string> DefaultValues { get; private set; }

        public Class IdentifiedClass { get; private set; }

        public override TypeReference Type
        {
            get { return type; }
        }

        public void AddPossibleIdentifiedClass(Class c)
        {
            if (IdentifiedClass == null)
            {
                IdentifiedClass = c;
            }
            else if (c != null)
            {
                IdentifiedClass = c.TypeSystem.GetCommonBase(c, IdentifiedClass);
            }
        }

        public override BnfExpression CreateRule(AnyTextGrammar grammar)
        {
            return Rule;
        }
    }
}
